package cn.iocoder.yudao.module.call.service.aiqualitytestingelsecondition;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.call.controller.admin.aiqualitytestingelsecondition.vo.*;
import cn.iocoder.yudao.module.call.dal.dataobject.aiqualitytestingelsecondition.AiQualityTestingElseConditionDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.call.dal.mysql.aiqualitytestingelsecondition.AiQualityTestingElseConditionMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.call.enums.ErrorCodeConstants.*;

/**
 * 大模型质检其他条件 Service 实现类
 *
 * @author 数创万维
 */
@Service
@Validated
public class AiQualityTestingElseConditionServiceImpl implements AiQualityTestingElseConditionService {

    @Resource
    private AiQualityTestingElseConditionMapper aiQualityTestingElseConditionMapper;

    @Override
    public Long createAiQualityTestingElseCondition(AiQualityTestingElseConditionSaveReqVO createReqVO) {
        // 插入
        AiQualityTestingElseConditionDO aiQualityTestingElseCondition = BeanUtils.toBean(createReqVO, AiQualityTestingElseConditionDO.class);
        aiQualityTestingElseConditionMapper.insert(aiQualityTestingElseCondition);
        // 返回
        return aiQualityTestingElseCondition.getId();
    }

    @Override
    public void updateAiQualityTestingElseCondition(AiQualityTestingElseConditionSaveReqVO updateReqVO) {
        // 校验存在
        validateAiQualityTestingElseConditionExists(updateReqVO.getId());
        // 更新
        AiQualityTestingElseConditionDO updateObj = BeanUtils.toBean(updateReqVO, AiQualityTestingElseConditionDO.class);
        aiQualityTestingElseConditionMapper.updateById(updateObj);
    }

    @Override
    public void deleteAiQualityTestingElseCondition(Long id) {
        // 校验存在
        validateAiQualityTestingElseConditionExists(id);
        // 删除
        aiQualityTestingElseConditionMapper.deleteById(id);
    }

    private void validateAiQualityTestingElseConditionExists(Long id) {
        if (aiQualityTestingElseConditionMapper.selectById(id) == null) {
            throw exception(AI_QUALITY_TESTING_ELSE_CONDITION_NOT_EXISTS);
        }
    }

    @Override
    public AiQualityTestingElseConditionDO getAiQualityTestingElseCondition(Long id) {
        return aiQualityTestingElseConditionMapper.selectById(id);
    }

    @Override
    public PageResult<AiQualityTestingElseConditionDO> getAiQualityTestingElseConditionPage(AiQualityTestingElseConditionPageReqVO pageReqVO) {
        return aiQualityTestingElseConditionMapper.selectPage(pageReqVO);
    }

}